<?php

/**
 * Role heirarchy model
 *
 * @author    Mon Zafra <monzee at gmail>
 * @copyright (c)2009 Mon Zafra
 * @license   http://monzee.wordpress.com/license New BSD
 * @version   $Id: RoleInheritance.php 38 2009-02-18 17:12:39Z monzee $
 */
class Admin_RoleInheritance
{
    protected $_roleInheritance;

    public function __construct()
    {
        $this->_roleInheritance = array(
            array(
                'parent_id' => 2, // Guest
                'child_id'  => 3, // Member
            ),
            array(
                'parent_id' => 2, // Guest
                'child_id'  => 3, // Member
            ),
            array(
                'parent_id' => 3, // Member
                'child_id'  => 4, // Author
            ),
            array(
                'parent_id' => 3, // Member
                'child_id'  => 5, // Moderator
            ),
            array(
                'parent_id' => 4, // Author
                'child_id'  => 6, // Editor
            ),
            array(
                'parent_id' => 5, // Moderator
                'child_id'  => 6, // Editor
            ),
        );
    }

    public function setRoleInheritance($roleInheritance)
    {
        $this->_roleInheritance = $roleInheritance;
    }

    public function getParentRoles($childId)
    {
        $map = $this->_roleInheritance;

        $ret = array();
        foreach ($map as $relation) {
            if ($relation['child_id'] == $childId) {
                $ret[] = $relation['parent_id'];
            }
        }

        return $ret;
    }

}
